<?php

interface ArticleDao {
	public function getArticles($sectionId, $isHome);
}

class ArticleDaoImpl implements ArticleDao {
	public function getArticles($sectionId, $isHome) {
		if (!mysql_connect("localhost", "root", "password") || !mysql_select_db("nettuts")) {
			throw new Exception(mysql_error());
		} 	

		$q = "SELECT " . 
		implode(",", array(
			"a.id",	
			"a.title"
		)) .  
		" FROM 	article a
		LEFT JOIN features f ON a.id = f.article_id 
		WHERE f.section_id = $sectionId 
		";

		$resource = mysql_query($q);
		
		if ($resource === false) {
			throw new Exception(mysql_error());
		}


		$articles = array();
		while($row = mysql_fetch_array($resource))  {
			$article = array();
			$article['id'] = $row['id'];
			$article['title'] = $row['title'];

			$articles[] = $article; 
		}
	
		return $articles;
	}	
} 
